﻿@model ItemModel
@using NewLife;
@using NewLife.Cube
@using XCode;
@using XCode.Configuration;
@{
    // value为空时，必须是空字符串，否则Html.TextBox显示Name字段时出问题，value也会由空变为Name
    var name = Model.Name;
    var value = Model.Value + "";
    var type = Model.Type;
    var length = Model.Length;

    var atts = HtmlHelper.AnonymousObjectToHtmlAttributes(Model.HtmlAttributes);
    if (!atts.ContainsKey("class")) atts.Add("class", "form-control");
}
@if (name.EqualIgnoreCase("Pass", "Password"))
{
    if (!atts.ContainsKey("autocomplete")) atts.Add("autocomplete", "off");
    @Html.Password(name, value, atts)
}
else if (name.EqualIgnoreCase("Phone", "TelPhone", "OfficePhone", "HomePhone", "Fax"))
{
    if (!atts.ContainsKey("type")) atts.Add("type", "tel");
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-phone-alt"></i></span>
        @Html.TextBox(name, value, atts)
    </div>
}
else if (name.EqualIgnoreCase("Mobile", "MobilePhone", "CellularPhone"))
{
    if (!atts.ContainsKey("type")) atts.Add("type", "tel");
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-phone"></i></span>
        @Html.TextBox(name, value, atts)
    </div>
}
else if (name.EqualIgnoreCase("email", "mail"))
{
    if (!atts.ContainsKey("type")) atts.Add("type", "email");
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
        @Html.TextBox(name, value, atts)
    </div>
}
else if (name.EndsWithIgnoreCase("url"))
{
    //if (!atts.ContainsKey("type")) atts.Add("type", "url");
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
        @Html.TextBox(name, value, atts)
    </div>
}
else if (length < 0 || length >= 300 || (length >= 200 && name.EqualIgnoreCase("Remark", "Description", "Comment")))
{
    @Html.TextArea(name, value, 3, 20, atts)
}
else
{
    @Html.TextBox(name, value, atts)
}